home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / gfx / show / gs_src_gs.lha / gs5.03 / gdevmiff.c < prev    next >
C/C++ Source or Header  |  1996-02-28  |  3KB  |  85 lines

  1. /* Copyright (C) 1996 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gdevmiff.c */
  20. /* MIFF file format driver */
  21. #include "gdevprn.h"
  22.  
  23. /* ------ The device descriptor ------ */
  24.  
  25. /*
  26.  * Default X and Y resolution.
  27.  */
  28. #define X_DPI 72
  29. #define Y_DPI 72
  30.  
  31. private dev_proc_print_page(miff24_print_page);
  32.  
  33. private gx_device_procs miff24_procs =
  34.   prn_color_procs(gdev_prn_open, gdev_prn_output_page, gdev_prn_close,
  35.     gx_default_rgb_map_rgb_color, gx_default_rgb_map_color_rgb);
  36. gx_device_printer far_data gs_miff24_device =
  37.   prn_device(miff24_procs, "miff24",
  38.          DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  39.          X_DPI, Y_DPI,
  40.          0,0,0,0,            /* margins */
  41.          24, miff24_print_page);
  42.  
  43. /* Print one page in 24-bit RLE direct color format. */
  44. private int
  45. miff24_print_page(gx_device_printer *pdev, FILE *file)
  46. {    int raster = gx_device_raster((gx_device *)pdev, true);
  47.     byte *line = (byte *)gs_malloc(raster, 1, "miff line buffer");
  48.     int y;
  49.     int code = 0;            /* return code */
  50.  
  51.     if ( line == 0 )        /* can't allocate line buffer */
  52.       return_error(gs_error_VMerror);
  53.     fputs("id=ImageMagick\n", file);
  54.     fputs("class=DirectClass\n", file);
  55.     fprintf(file, "columns=%d\n", pdev->width);
  56.     fputs("compression=RunlengthEncoded\n", file);
  57.     fprintf(file, "rows=%d\n", pdev->height);
  58.     fputs(":\n", file);
  59.     for ( y = 0; y < pdev->height; ++y )
  60.       {    byte *row;
  61.         byte *end;
  62.  
  63.         code = gdev_prn_get_bits(pdev, y, line, &row);
  64.         if ( code < 0 )
  65.           break;
  66.         end = row + pdev->width * 3;
  67.         while ( row < end )
  68.           { int count = 0;
  69.             while ( count < 255 && row < end - 3 &&
  70.                 row[0] == row[3] && row[1] == row[4] &&
  71.                 row[2] == row[5]
  72.               )
  73.               ++count, row += 3;
  74.             putc(row[0], file);
  75.             putc(row[1], file);
  76.             putc(row[2], file);
  77.             putc(count, file);
  78.             row += 3;
  79.           }
  80.       }
  81.     gs_free((char *)line, lsize, 1, "miff line buffer");
  82.  
  83.     return code;
  84. }
  85.